"use strict";
cc._RF.push(module, 'c2c71BhPrdKTb24dMTeJvWH', 'AccelerometerMgr');
// scripts/Game/AccelerometerMgr.ts

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
//电子邮件puhalskijsemen@gmail.com
//源码网站 开vpn全局模式打开 http://web3incubators.com/
//电报https://t.me/gamecode999
//网页客服 http://web3incubators.com/kefu.html
var hall_1 = require("../scenes/hall");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var AccelerometerMgr = /** @class */ (function () {
    function AccelerometerMgr() {
    }
    /**
    *
    * @param AccFun(res) 加速度计变化时的运行逻辑  res ：{x,y,z}
    */
    AccelerometerMgr.StartAccelerometer = function (AccFun) {
        var _this = this;
        console.log("调用了");
        switch (cc.sys.platform) {
            case cc.sys.WECHAT_GAME_SUB:
            case cc.sys.WECHAT_GAME: {
                // if(cc.s)
                this.VivoAccFunes.push(AccFun);
                window["wx"].startAccelerometer({
                    interval: 'game',
                    success: function () { console.log("调用加速度计成功！"); },
                    fail: function () { console.log("加速度计调用失败！"); },
                    complete: function () { console.log("尝试调用加速度计！"); }
                });
                window["wx"].onAccelerometerChange(function (res) {
                    var funes = _this.VivoAccFunes;
                    var dir = null;
                    // console.log("????")
                    for (var index = 0; index < funes.length; index++) {
                        var element = funes[index];
                        if (hall_1.default.PlatFrom == "ios") {
                            dir = res;
                            dir.x *= -1;
                            dir.y *= -1;
                            dir.z *= -1;
                        }
                        else {
                            dir = res.result;
                        }
                        element && element(dir);
                    }
                });
                break;
            }
            case cc.sys.BYTEDANCE_GAME:
            case cc.sys.BYTEDANCE_GAME_SUB: {
                window["tt"].startAccelerometer({
                    success: function (res) { console.log(res.errMsg, "加速度计调用成功！"); },
                    fail: function (res) { console.log(res.errMsg, "加速度计调用失败！"); },
                    complete: function () { console.log("尝试调用加速度计！"); }
                });
                window["tt"].onAccelerometerChange(function (res) {
                    // console.warn(res);
                    AccFun && AccFun({ x: -res.x * 10, y: -res.y * 10, z: -res.z * 10 });
                });
                break;
            }
            case cc.sys.VIVO_GAME: {
                window['qg'].subscribeCompass({
                    callback: function (res) {
                        AccFun && AccFun(res);
                    }
                });
                break;
            }
            case cc.sys.OPPO_GAME: {
                window["qg"].startAccelerometer({
                    success: function (res) { console.log(res.errMsg, "加速度计调用成功！"); },
                    fail: function (res) { console.log(res.errMsg, "加速度计调用失败！"); },
                    complete: function () { console.log("尝试调用加速度计！"); }
                });
                window["qg"].onAccelerometerChange(function (res) {
                    AccFun && AccFun(res);
                });
                break;
            }
            default: {
                if (cc.sys.isNative) {
                }
                else {
                    if (cc.sys.platform == 3 || cc.sys.platform == 4) {
                        window['kwaigame'].startDeviceMotionListening({
                            interval: "game",
                            success: function (res) { console.log(res.errMsg, "加速度计调用成功！"); },
                            fail: function (res) { console.log(res.errMsg, "加速度计调用失败！"); },
                            complete: function () { console.log("尝试调用加速度计！"); }
                        });
                        window['kwaigame'].onDeviceMotionChange(function (res) {
                            var r = {};
                            r.x = res.alpha;
                            r.y = res.beta;
                            r.z = res.gamma;
                            AccFun && AccFun(r);
                        });
                    }
                    else {
                        this.AccelerFun = function (res) {
                            var r = res.accelerationIncludingGravity;
                            AccFun(r);
                        };
                        //devicemotion
                        //deviceorientation
                        window.addEventListener('devicemotion', this.AccelerFun, false);
                    }
                }
                break;
            }
        }
    };
    AccelerometerMgr.StopAccelerometerFun = function () {
    };
    AccelerometerMgr.StopAccelerometer = function () {
        switch (cc.sys.platform) {
            case cc.sys.WECHAT_GAME_SUB:
            case cc.sys.WECHAT_GAME: {
                // 微信
                window["wx"].stopAccelerometer({
                    success: function () { console.log("停用加速度计成功！"); },
                    fail: function () { console.log("停用加速度计失败！"); },
                    complete: function () { console.log("尝试停用加速度计"); }
                });
                this.VivoAccFunes = [];
                break;
            }
            case cc.sys.BYTEDANCE_GAME:
            case cc.sys.BYTEDANCE_GAME_SUB: {
                //头条
                window["tt"].stopAccelerometer({
                    success: function () { console.log("停用加速度计成功！"); },
                    fail: function () { console.log("停用加速度计失败！"); },
                    complete: function () { console.log("尝试停用加速度计"); }
                });
                break;
            }
            case cc.sys.VIVO_GAME: {
                window['qg'].subscribeCompass({
                    callback: function (data) {
                        console.log("停用加速度计");
                    }
                });
                break;
            }
            case cc.sys.OPPO_GAME: {
                window['qg'].stopAccelerometer({
                    success: function () { console.log("停用加速度计成功！"); },
                    fail: function () { console.log("停用加速度计失败！"); },
                    complete: function () { console.log("尝试停用加速度计"); }
                });
                break;
            }
            default: {
                if (cc.sys.isNative) {
                }
                else {
                    if (cc.sys.platform == 3 || cc.sys.platform == 4) {
                        //TODO 快手加速计  由于快手没有加速计这里使用的是获取设备方向接口
                        window["kwaigame"].stopDeviceMotionListening();
                    }
                    else {
                        window.removeEventListener("devicemotion", this.AccelerFun, false);
                    }
                }
                break;
            }
        }
    };
    AccelerometerMgr.AccelerFun = null;
    AccelerometerMgr.VivoAccFunes = [];
    AccelerometerMgr = __decorate([
        ccclass
    ], AccelerometerMgr);
    return AccelerometerMgr;
}());
exports.default = AccelerometerMgr;

cc._RF.pop();